<?php
/**
 * 解释器模式
 * This file is part of pattern.
 * Author: tangzhou
 * Date: 2016/9/5
 * Time: 15:42
 * File: interpreter.php
 */

class PlayContent
{
    public $content;
}

abstract class IExpress
{
    public function Translate(PlayContent $playContent)
    {
        $key = substr($playContent->content, 1, 2);
        $val = substr($playContent->content, 2, 5);
        $this->execute($key, $val);
    }
    abstract public function execute($key, $val);
}

/**
 * Class Demo1
 */
class Demo1 extends IExpress
{
    public function execute($key, $val)
    {
        switch ($key)
        {
            case 1:
                return 'xx';
                break;
            case 2:
                return 'oo';
            break;
        }
        return "00";
    }
}

/**
 * Class Demo1
 */
class Demo2 extends IExpress
{
    public function execute($key, $val)
    {
        switch ($val)
        {
            case 1:
                return 'xx';
                break;
            case 2:
                return 'oo';
                break;
        }
        return "00";
    }
}

$playContent = new PlayContent();
$playContent->content = "11123213";

$interpreter = new Demo1();
$interpreter->Translate($playContent);

